package cn.edu.wfit.modules.infomanagement.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.edu.wfit.common.log.annotation.Log;
import cn.edu.wfit.common.log.enums.BusinessType;
import cn.edu.wfit.common.security.annotation.RequiresPermissions;
import cn.edu.wfit.modules.infomanagement.domain.Dormbuilding;
import cn.edu.wfit.modules.infomanagement.service.IDormbuildingService;
import cn.edu.wfit.common.core.web.controller.BaseController;
import cn.edu.wfit.common.core.web.domain.AjaxResult;
import cn.edu.wfit.common.core.utils.poi.ExcelUtil;
import cn.edu.wfit.common.core.web.page.TableDataInfo;

/**
 * 书院维护Controller
 * 
 * @author 韩强
 * @date 2024-11-18
 */
@RestController
@RequestMapping("/dormbuilding")
public class DormbuildingController extends BaseController
{
    @Autowired
    private IDormbuildingService dormbuildingService;

    /**
     * 查询书院维护列表
     */
    @RequiresPermissions("system:dormbuilding:list")
    @GetMapping("/list")
    public TableDataInfo list(Dormbuilding dormbuilding)
    {
        startPage();
        List<Dormbuilding> list = dormbuildingService.selectDormbuildingList(dormbuilding);
        return getDataTable(list);
    }

    /**
     * 导出书院维护列表
     */
    @RequiresPermissions("system:dormbuilding:export")
    @Log(title = "书院维护", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Dormbuilding dormbuilding)
    {
        List<Dormbuilding> list = dormbuildingService.selectDormbuildingList(dormbuilding);
        ExcelUtil<Dormbuilding> util = new ExcelUtil<Dormbuilding>(Dormbuilding.class);
        util.exportExcel(response, list, "书院维护数据");
    }

    /**
     * 获取书院维护详细信息
     */
    @RequiresPermissions("system:dormbuilding:query")
    @GetMapping(value = "/{dormbuildingId}")
    public AjaxResult getInfo(@PathVariable("dormbuildingId") Long dormbuildingId)
    {
        return success(dormbuildingService.selectDormbuildingByDormbuildingId(dormbuildingId));
    }

    /**
     * 新增书院维护
     */
    @RequiresPermissions("system:dormbuilding:add")
    @Log(title = "书院维护", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Dormbuilding dormbuilding)
    {
        return toAjax(dormbuildingService.insertDormbuilding(dormbuilding));
    }

    /**
     * 修改书院维护
     */
    @RequiresPermissions("system:dormbuilding:edit")
    @Log(title = "书院维护", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Dormbuilding dormbuilding)
    {
        return toAjax(dormbuildingService.updateDormbuilding(dormbuilding));
    }

    /**
     * 删除书院维护
     */
    @RequiresPermissions("system:dormbuilding:remove")
    @Log(title = "书院维护", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dormbuildingIds}")
    public AjaxResult remove(@PathVariable Long[] dormbuildingIds)
    {
        return toAjax(dormbuildingService.deleteDormbuildingByDormbuildingIds(dormbuildingIds));
    }
}
